const app = getApp();
var util = require('../../utils/util.js')
var http = require('../../utils/server.js')
// pages/banghui/details.js
Page({

  data: {
    showDialog: false,
    data: {},
    id: null,
    gang_role: 0,
  },

  onLoad: function(options) {
    var that = this;

    that.data.id = options.id;
    try {
      var value = wx.getStorageSync('userInfo');
      console.info(value);
      if (value) {
        that.data.gang_role = value.gangRole;
      }
    } catch (e) {}


  },
  onShow: function () {
    var that = this;
    http.post({
      url: "Gang/getInfo",
      gang_id: that.data.id,
      type: ''
    }, function(data) {
      console.log('帮会信息', data);
      that.setData({
        data: data,
        gang_role: that.data.gang_role
      });
    })
  },
  exit: function() {
    wx.showModal({
      title: '操作提示',
      content: '确定退出帮会?',
      success: function(res) {
        if (res.confirm) {
          http.post({
            url: "Gang/exitGang",
          }, function(data) {
            util.showSuccess('退出成功', function () {
              wx.setStorageSync('userInfo', null); 
              wx.reLaunch({
                url: '/pages/index/welcome'
              })
            })
          })
        }
      }
    })
  },
  chengyuan: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/banghui/chengyuan?gang_id=' + that.data.data.id,
    })
  },
  concat: function() {
    this.setData({
      showDialog: true,
    })
  },
  toggleDialog: function() {
    this.setData({
      showDialog: false,
    })
  },
  fensijiangli: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/banghui/fensijiangli?gang_id=' + that.data.data.id,
    })
  },
  yaoqing: function() {
    wx.navigateTo({
      url: '/pages/banghui/inviter?bangzhu=1',
    })
  },
  setting: function() {
    var that = this;
    wx.navigateTo({
      url: '/pages/banghui/setting?gang_id=' + that.data.data.id,
    })
  },
  call() {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.data.phone
    })
  },
  copy() {
    var that = this;
    wx.setClipboardData({
      data: that.data.data.wx_number,
      success: function(res) {

      }
    })
  },
  saveImg() {
    var that = this;
    wx.getImageInfo({
      src: that.data.data.wx_qrcode,
      success: function(res) {
        console.log(res.path)
        wx.saveImageToPhotosAlbum({
          filePath: res.path,
          success(res) {
            console.info(res)
          },
          fail(res) {
            console.info(res)
          }
        })
      }
    })
  }
})